package cn.itcast;

import java.sql.*;

public class KylinTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /**
         * 数据库驱动：org.apache.kylin.jdbc.Driver
         * url ：      jdbc:kylin://node01:7070/kylin（数据库名）
         * 用户名：   ADMIN
         * 密码：     KYLIN
         */
        Class.forName("org.apache.kylin.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:kylin://node01:7070/itcast_quot_dm", "ADMIN", "KYLIN");
        String sql = "select\n" +
                "    sec_code,trade_date,\n" +
                "       max(high_price) as high_price,\n" +
                "       min(low_price) as low_price,\n" +
                "       max(trade_vol_day) as max_vol_day,\n" +
                "       min(trade_vol_day) as min_vol_day,\n" +
                "       max(trade_amt_day) as max_amt_day,\n" +
                "       min(trade_amt_day) as min_amt_day\n" +
                "from app_sec_quot_stock\n" +
                "where trade_date between '2022-05-10' and '2022-05-18'\n" +
                "group by sec_code,trade_date";
        PreparedStatement prep = conn.prepareStatement(sql);
        ResultSet resultSet = prep.executeQuery();
        while (resultSet.next()){
            String result= resultSet.getString(1)+" "+resultSet.getString(2);
            System.out.println(result);
        }

        resultSet.close();
        prep.close();
        conn.close();
    }
}
